<template>
    <div class="contract-create-template">
        <el-button class="return" type="text" @click="jumpToDefault"><i class="fa fa-angle-left mr5"></i>返回</el-button>
        <h4 class="header">创建合同信息</h4>
        <div class="content">
            <div class="filter-section">
                <span class="fl title">合同基本信息</span>
                <span class="fr gray">注：带有*为必填项</span>
            </div>
            <div class="contract-form">
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px">
                    <el-form-item label="合同名称" prop="contractName">
                        <el-input v-model="ruleForm.contractName" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="机构名称" prop="instituName">
                        <el-input v-model="ruleForm.insitituName" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="购买产品类别" prop="productType">
                        <el-checkbox-group v-model="ruleForm.productType">
                            <el-checkbox label="博看专区" name="type"></el-checkbox>
                            <el-checkbox label="手机APP" name="type"></el-checkbox>
                            <el-checkbox label="微刊" name="type"></el-checkbox>
                            <el-checkbox label="触摸屏" name="type"></el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item label="服务方式" prop="serviceMode">
                        <el-checkbox-group v-model="ruleForm.serviceMode">
                            <el-checkbox label="镜像" name="type"></el-checkbox>
                            <el-checkbox label="远程" name="type"></el-checkbox>
                            <el-checkbox label="馆外用户名" name="type"></el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item label="资源范围" prop="resourceArea">
                        <el-checkbox-group v-model="ruleForm.resourceArea">
                            <el-checkbox label="全选" name="type"></el-checkbox>
                            <el-checkbox label="期刊" name="type"></el-checkbox>
                            <el-checkbox label="报志" name="type"></el-checkbox>
                            <el-checkbox label="图书" name="type"></el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item label="合同性质" prop="property">
                        <el-select v-model="ruleForm.property" size="mini">
                            <el-option label="区域一" value="shanghai"></el-option>
                            <el-option label="区域二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="合同类型" prop="type">
                        <el-select v-model="ruleForm.type" size="mini">
                            <el-option label="区域一" value="shanghai"></el-option>
                            <el-option label="区域二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="合同经办人" prop="operator">
                        <el-input v-model="ruleForm.operator" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="合同联系人" prop="contact">
                        <el-input v-model="ruleForm.contact" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="合同总金额" prop="totalMoney">
                        <el-input v-model="ruleForm.totalMoney" size="mini"></el-input>
                        元
                    </el-form-item>
                    <el-form-item label="付款方式" prop="payMethod">
                        <el-select v-model="ruleForm.payMethod" size="mini">
                            <el-option label="区域一" value="shanghai"></el-option>
                            <el-option label="区域二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="签约日期" prop="contractDate">
                        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.contractDate"
                                        size="mini"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="合同期限">
                        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.start" size="mini"
                                        class="start"></el-date-picker>
                        <span class="split">至</span>
                        <el-time-picker type="date" placeholder="选择日期" v-model="ruleForm.end" size="mini"
                                        class="end"></el-time-picker>
                    </el-form-item>
                    <el-form-item label="负责代理" prop="agency">
                        <el-input v-model="ruleForm.agency" size="mini"></el-input>
                    </el-form-item>
                </el-form>
            </div>
            <div class="filter-section">
                <span class="fl title">合同相关信息</span>
                <span class="fr gray">注：带有*为必填项</span>
            </div>
            <div class="contract-form">
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
                    <el-form-item label="博看签字人" prop="BKSignatory">
                        <el-input v-model="ruleForm.BKSignatory" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="机构签字人" prop="JGSignatory">
                        <el-input v-model="ruleForm.JGSignatory" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="审核状态" prop="audietStatus">
                        <el-select v-model="ruleForm.audietStatus" size="mini">
                            <el-option label="区域一" value="shanghai"></el-option>
                            <el-option label="区域二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="合同到期提醒" prop="remind">
                        <el-radio-group v-model="ruleForm.remind">
                            <el-radio label="1">开启</el-radio>
                            <el-radio label="0">关闭</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="合同扫描件" prop="scan" class="simple-fl">
                        <el-upload
                                class="upload-file"
                                action="https://jsonplaceholder.typicode.com/posts/"
                                :on-preview="handlePreview"
                                :on-remove="handleRemove"
                                :before-remove="beforeRemove"
                                multiple
                                :limit="1"
                                :file-list="ruleForm.scan">
                            <el-button size="mini" type="primary">上传合同</el-button>
                            <div slot="tip" class="el-upload__tip fr">注：上传纸质合同扫描件，图片格式JPG或PNG，文件大小不超过2M</div>
                        </el-upload>
                    </el-form-item>
                    <el-form-item label="备注" prop="ZQNote" class="form-textarea">
                        <el-input type="textarea" v-model="ruleForm.ZQNote" size="mini"></el-input>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <div class="btn-wrap">
            <el-button type="primary" @click="submitForm('ruleForm')">确定</el-button>
            <el-button @click="cancelForm()">取消</el-button>
        </div>
    </div>
</template>

<script>
    export default {
        name: "ContractCreate",
        data() {
            return {
                ruleForm: {
                    contractName: "",
                    insitituName: "",
                    productType: [],
                    serviceMode: [],
                    resourceArea: [],
                    property: "",
                    type: "",
                    operator: "",
                    contact: "",
                    totalMoney: "",
                    payMethod: "",
                    contractDate: "",
                    start: "",
                    end: "",
                    agency: "",
                    BKSignatory: "",
                    JGSignatory: "",
                    ZQNote: "",
                    scan: [],
                    audietStatus: "",
                    remind: "",
                },
                rules: {
                    contractName: [
                        {required: true, message: '请输入合同名称', trigger: 'blur'}
                    ],
                    instituName: [
                        {required: true, message: '请输入机构名称', trigger: 'blur'}
                    ],
                    productType: [
                        {required: true, message: '请选择产品类别', trigger: 'change'}
                    ],
                    serviceMode: [
                        {required: true, message: '请选择服务方式', trigger: 'change'}
                    ],
                    resourceArea: [
                        {required: true, message: '请选择资源范围', trigger: 'change'}
                    ],
                    property: [
                        {required: true, message: '请选择合同性质', trigger: 'change'}
                    ],
                    type: [
                        {required: true, message: '请选择合同类型', trigger: 'change'}
                    ],
                    operator: [
                        {required: true, message: '请输入经办人', trigger: 'blur'}
                    ],
                    contact: [
                        {required: true, message: '请输入联系人', trigger: 'blur'}
                    ],
                    totalMoney: [
                        {required: true, message: '请输入总金额', trigger: 'blur'}
                    ],
                    payMethod: [
                        {required: true, message: '请选择付款方式', trigger: 'change'}
                    ],
                    contractDate: [
                        {required: true, message: '请选择签约日期', trigger: 'change'}
                    ],
                    agency: [
                        {required: true, message: '请输入负责代理', trigger: 'blur'}
                    ],
                    BKSignatory: [
                        {required: true, message: '请输入博看签字人', trigger: 'blur'}
                    ],
                    JGSignatory: [
                        {required: true, message: '请输入机构签字人', trigger: 'blur'}
                    ],
                }
            }
        },
        methods: {
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePreview(file) {
                console.log(file);
            },
            beforeRemove(file, fileList) {
                return this.$confirm(`确定移除 ${file.name}？`);
            },
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        console.log('submit!');
                        this.jumpToDefault();
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            cancelForm() {
                this.jumpToDefault();
            },
            jumpToDefault() {
                this.$parent.curPath = 'default';
            }
        }
    }
</script>

<style lang="scss">
    @import "src/common/common.style";
    .contract-create-template {
        background-color: #ffffff;
        width: 100%;
        height: 100%;
        position: relative;
        .return {
            position: absolute;
            top: 0;
            left: 15px;
            padding: 0;
        }
        .header {
            text-align: center;
        }
        .content {
            height: 85%;
            @include ofy-a();
            .filter-section {
                clear: both;
                border-bottom: 1px solid #ddd;
                padding-bottom: 25px;
                margin: 0 10px;
                padding-left: 5px;
                padding-right: 5px;
                .title {
                    font-size: $font-mn;
                    font-weight: 600;
                }
                .gray {
                    color: gray;
                }
            }
            .contract-form {
                padding-top: 10px;
                .el-form {
                    margin: 0 50px;
                    .el-form-item:not(.form-textarea) {
                        margin-bottom: 15px;
                        display: inline-block;
                        width: 50%;
                        .el-form-item__content {
                            @include fl();
                            margin-left: 0 !important;
                        }
                        .el-input {
                            width: 300px;
                        }
                    }
                    .el-upload__tip {
                        margin-top: 0;
                        padding-left: 5px;
                        color: #cccccc;
                    }
                    .simple-fl {
                        @include fl();
                    }
                    .start, .end {
                        width: 200px!important;
                        .el-input__inner{
                            width: 200px;
                        }
                    }
                    .split{
                        margin: 0 5px;
                    }
                    .form-textarea {
                        clear: both;
                        .el-textarea, .el-input__inner {
                            width: 80%;
                            float: left;
                            .el-textarea__inner {
                                min-height: 100px !important;
                            }
                        }
                    }
                }
            }
        }
        .btn-wrap {
            .el-button {
                width: 100px;
                margin: 0 50px;
            }
        }
    }
</style>